package com.ndp.fb.mq.consumer.autocontroll;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ndp.fb.constant.ConfigConst;
import com.ndp.fb.model.fbagent.param.ApiCallBackTarget;
import com.ndp.fb.mq.api.service.schedulerservice.business.AdGroupGCService;
import com.ndp.fb.mq.api.service.schedulerservice.business.syncbusiness.SyncAccountResourceService;
import com.ndp.fb.mq.consumer.AbstractPullConsumer;

/**
 * Created by Sisi on 15-2-27.
 */
@Component
public class AutoControllConsumerImpl extends AbstractPullConsumer {
    private static Logger logger = LoggerFactory.getLogger(AutoControllConsumerImpl.class);
    @Autowired
    private AdGroupGCService adGroupGCService;

    @Autowired
    private SyncAccountResourceService syncAccountResourceService;

    @Override
    public String getTopicName() {
        return ConfigConst.MQ_SERVICES_AUTOCONTROLL_TOPIC;
    }
    @Override
    protected void consume(String tag, String keys, Object message, Map<String, String> equipment) {
        logger.debug("AutoControllConsumerImpl tag >>>> " + tag + " keys >>>" + keys + " message >>> " + message);

        String body = message.toString();
        ApiCallBackTarget.AutoControl autoControl = (ApiCallBackTarget.AutoControl) ApiCallBackTarget.getTargetType(tag);

        switch (autoControl) {
            case AdGroupDelete:
                logger.info("ad 回收完成，回调====");
                adGroupGCService.adGroupDeleteCallBack(equipment, body);
                break;
            case SyncIns:
                syncAccountResourceService.syncAccountInsCallback(equipment, message);
                break;
            default:
                logger.warn("AutoControllConsumerImpl 不识别的消息tag >>>>" + tag + " ; message >>> " + message);
        }
    }
}
